<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    
    const Logo = {
      template: `
        <div>
            <h3>这是一个logo组件</h3>
            <button @click="emit">触发子组件自定义事件</button>
        </div>
      `,
      data(){
        return {
          msg: '这是子组件中的数据'
        }
      },
      methods: {
        emit(){
          this.$emit('biubiubiu', this.msg) // 事件触发
        }
      }
    }
    const CommonHead = {
      // 父组件中通过 子组件标签的自定义属性 传递数据
      template: `
        <div>
          <h2>我是父组件1</h2>  
          {{ msg }}
          <logo @biubiubiu="fn"></logo>
        </div>
      `,
      data(){
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg){
          console.log(msg);
          this.msg = msg;
        }
      },
      components: {
        Logo
      }
    };
    Vue.component('CommonHead', CommonHead);
    
    const vm = new Vue({
      el: '#app'
    })
 
  </script>
</body>
</html>